<?php
/**
 * @file top.php
 * @version 0.1
 * @desc 实时更新TOP信息
 */
?>
<!-- TOP Start -->
<table width="100%" height="100%" border="0" cellpadding="4" cellspacing="1" bgcolor="#012849">
<tr>
<td height="445" valign="top" bgcolor="#4484C1">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr><td height="25" align="center" bgcolor="#014075">
		<table width="96%" border="0" cellspacing="0" cellpadding="0"><tr><td width="60%" align="center">每个K宝价格(K币)</td><td width="40%" align="center">挂单数量(K宝)</td></tr></table>
	</td></tr>
</table>

	<div id="top-sell"></div><!-- #top-sell -->		          

          
<table width="50%" border="0" cellspacing="0" cellpadding="0">
	<tr><td height="7"></td></tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr><td height="2"bgcolor="3676B4"></td></tr>
</table>
<table width="50%" border="0" cellspacing="0" cellpadding="0">
	<tr><td height="7"></td></tr>
</table>
            
	<div id="top-buy"></div><!-- #top-buy --> 

<table width="50%" border="0" cellspacing="0" cellpadding="0">
	<tr><td height="7"></td></tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr><td height="25" align="center" bgcolor="#014075"><span class="blue1">交易说明</span></td></tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="120" align="center" bgcolor="#3676B4"><table width="95%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td>
        个人交易以K币作流通货币，以K宝<br />
          为交易对象，约定一个K宝为最小交易<br />
          单位。同时称一个K宝为一手。<br />
          <span class="yellow">交易风险自负，买卖均为玩家行为！</span></td>
      </tr>
    </table></td>
  </tr>
</table>
</td>
</tr>
</table>

<script type="text/javascript">
$(document).ready(function(){
	getTop();
	var iTime = setInterval(getTop, 5000);
	
	// 试用JSON传输数据，修正IE6下jQuery解析XML的错误
	function getTop(){
		$.post("bg-top-json-procedure.php", {
			action: 'getTop'
			}, function(data, textStatus){
				//alert( data );
				addMsg( data );
			}, 'json');
		
		$("#test").prepend( " Q " );
	} //END func getTop()
	
	function addMsg(data){
		$("#top-sell").empty();
		$("#top-buy").empty();
		var sell = 0;
		var buy = 1;

		if(data['msg'] == '403'){
			alert("主账户登出K秀系统！");
			window.location='?uin=<?php echo $user_id; ?>&module=login';
		}else		
		$.each(data['top'], function(i,n){
			if( n['flag'] == '4'){
				sell++;
				
			}else if( n['flag'] == '3'){
				if(buy%2 == 0) {
					var msg = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr bgcolor=\"#3676B4\"><td width=\"13%\" height=\"23\" class=\"yellow\">买"
						+buy+"</td><td width=\"51%\" align=\"center\">"
						+n['price']+"K币</td><td width=\"36%\" align=\"center\">"
						+n['num']+"手</td></tr></table>";
				}else
					var msg = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"13%\" height=\"23\" class=\"yellow\">买"
							+buy+"</td><td width=\"51%\" align=\"center\">"
							+n['price']+"K币</td><td width=\"36%\" align=\"center\">"
							+n['num']+"手</td></tr></table>";
				$("#top-buy").append( msg );
				buy++;
			}//END buy
		});
		$.each(data['top'], function(i,n){
			if( n['flag'] == '4'){
				if(sell%2 == 0) {
					var msg = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr bgcolor=\"#3676B4\"><td width=\"13%\" height=\"23\" class=\"yellow\">卖"
						+sell+"</td><td width=\"51%\" align=\"center\">"
						+n['price']+"K币</td><td width=\"36%\" align=\"center\">"
						+n['num']+"手</td></tr></table>";
				}else
					var msg = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"13%\" height=\"23\" class=\"yellow\">卖"
							+sell+"</td><td width=\"51%\" align=\"center\">"
							+n['price']+"K币</td><td width=\"36%\" align=\"center\">"
							+n['num']+"手</td></tr></table>";
				$("#top-sell").append( msg );
				sell--;
			}
		});
		
	} //END func addMsg
});
</script>
<!-- TOP Stop -->